package com.lonely.fx;

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.control.Button;
import javafx.scene.control.CustomMenuItem;
import javafx.scene.control.Menu;
import javafx.scene.control.MenuBar;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;

/**
 * @date: 2022-07-07 14:18
 * @author: ztkj-hzb
 * @description: 自定义菜单设置, 关键类：
 * CustomMenuItem： 本质上还是一个MenuItem，不过可以实现套娃
 **/
public class CustomMenuSettingMain extends Application {

    public static void main(String[] args) {
        launch(args);
    }

    /**
     *
     */
    @Override
    public void start(Stage primaryStage) throws Exception {

        BorderPane borderPane = new BorderPane();

        MenuBar menuBar = new MenuBar();
        menuBar.setStyle("-fx-background-color: pink");
        borderPane.setTop(menuBar);

        Menu menu = new Menu("New");

        //自定义菜单项：按钮
        CustomMenuItem customMenuItem = new CustomMenuItem();
        customMenuItem.setContent(new Button("按钮1"));

        //自定义菜单项：布局
        CustomMenuItem paneMenu = new CustomMenuItem();
        HBox hBox = new HBox();
        hBox.setPrefWidth(200);
        hBox.setPrefHeight(200);
        hBox.setStyle("-fx-background-color: red");
        hBox.getChildren().addAll(new Button("Button1"), new Button("Button2"));
        paneMenu.setContent(hBox);

        menu.getItems().addAll(customMenuItem, paneMenu);

        menuBar.getMenus().addAll(menu);
        primaryStage.setScene(new Scene(borderPane));
        primaryStage.setWidth(600);
        primaryStage.setHeight(500);
        primaryStage.show();

    }
}
